//
//  ViolationCodeCell.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/5/18.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import UIKit

class ViolationCodeCell: UITableViewCell {
    var codeLabel,scoreLabel,moneyLabel,contentLabel:UILabel!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.backgroundColor = tableBgColor
        self.setupMainView()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupMainView() {
        // 背景view
        let backgroundView = UIView()
        backgroundView.layer.borderColor = colorFromHex(0xeeeeee).cgColor
        backgroundView.layer.borderWidth = 1
        backgroundView.layer.cornerRadius = 5
        backgroundView.layer.masksToBounds = true
        backgroundView.backgroundColor = UIColor.white
        backgroundView.autoresizingMask = .flexibleHeight
        self.addSubview(backgroundView)
        backgroundView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(5)
            make.top.equalTo(self).offset(5)
            make.right.equalTo(self).offset(-5)
            make.bottom.equalTo(self)
        }
        codeLabel = UILabel()
        codeLabel.textColor = appMainColor
        codeLabel.font = UIFont.systemFont(ofSize: 13)
        backgroundView.addSubview(codeLabel)
        codeLabel.snp.makeConstraints { (make) in
            make.height.equalTo(30)
            make.width.equalTo(kScreenW/3)
            make.top.equalTo(backgroundView.snp.top)
            make.left.equalTo(backgroundView.snp.left).offset(10)
        }
        
        scoreLabel = UILabel()
        scoreLabel.textColor = appMainColor
        scoreLabel.font = UIFont.systemFont(ofSize: 13)
        backgroundView.addSubview(scoreLabel)
        scoreLabel.snp.makeConstraints { (make) in
            make.height.equalTo(30)
            make.width.equalTo(55)
            make.left.equalTo(codeLabel.snp.right).offset(15)
            make.top.equalTo(backgroundView.snp.top)
        }
        moneyLabel = UILabel()
        moneyLabel.textColor = appMainColor
        moneyLabel.font = UIFont.systemFont(ofSize: 13)
        backgroundView.addSubview(moneyLabel)
        moneyLabel.snp.makeConstraints { (make) in
            make.height.equalTo(30)
            make.width.equalTo(kScreenW/3)
            make.left.equalTo(scoreLabel.snp.right).offset(30)
            make.top.equalTo(backgroundView.snp.top)
        }
        contentLabel = UILabel()
        contentLabel.font = UIFont.systemFont(ofSize: 13)
        contentLabel.textColor = UIColor.gray
        contentLabel.numberOfLines = 0
        contentLabel.lineBreakMode = .byCharWrapping
        backgroundView.addSubview(contentLabel)
        contentLabel.snp.makeConstraints { (make) in
            make.top.equalTo(codeLabel.snp.bottom)
            make.left.equalTo(backgroundView.snp.left).offset(5)
            make.bottom.equalTo(backgroundView.snp.bottom).offset(-5)
            make.right.equalTo(backgroundView.snp.right).offset(-3)
            
        }
    }
    func configCellDateWithModel(_ model:ViolationCodeModel) {
        codeLabel.text = "代码：\(model.code)"
        scoreLabel.text = "扣分：\(model.score)"
        moneyLabel.text = "罚款：\(model.price)"
        contentLabel.text = model.remark
    }
}
